const ActSignScore = require('../model/actSignScore.model')

class ActSignScoreService {
    /**
     * 新增活动签到的分数
     */
    async addactSignScore (actSignScoreData) {
        // 插入数据
        try {
            const res = await ActSignScore.create(actSignScoreData)
            return res
        } catch (error) {
            return {
                errorFlag: 'error',
                message: error,
            }
        }
    }

    /**
     * 删除某活动的加分
     */
    async deleteactSignScore (act_id) {
        const res = await ActSignScore.destroy({ where: { act_id } })
    }

    /**
     * 通过活动id和分数类型获取某条活动分数表
     */
    async getOneActSignScore ({ act_id, score_type }) {
        try {
            const res = await ActSignScore.findOne({ act_id, score_type })
            return res
        } catch (error) {
            return {
                errorFlag: 'error',
                message: error,
            }
        }
    }

    /**
     * 通过活动id获取加分类型表
     */
    async getActSignScoreListByActId (act_id) {
        try {
            const res = await ActSignScore.findAll({ where: { act_id } })
            return res
        } catch (error) {
            console.log(error)
            return {
                errorFlag: 'error',
                message: error,
            }
        }
    }
}

module.exports = new ActSignScoreService()